setTimeout(function(){
	html = newsCollectPanel();
	btn = shrinkBtn('腾讯面板');
	$('html body').append(btn);
	$('html body').append(html);

	//把默认时间填充到input
	start_time = getValidDate(1);
	spl_start_time = start_time.split('-');
	$('.start_year').val(spl_start_time[0]);
	$('.start_month').val(spl_start_time[1]);
	$('.start_day').val(spl_start_time[2]);
	
	end_time = getValidDate(0);
	spl_end_time = end_time.split('-');
	$('.end_year').val(spl_end_time[0]);
	$('.end_month').val(spl_end_time[1]);
	$('.end_day').val(spl_end_time[2]);

},2000);

/* 
选项卡切换
 */
$('html body').on('change','.mode',function () {
	mode = $(this).val();
	if(mode == 1){
		$('.sjjq').css('display','block')
		$('.psjq').css('display','none')
	}else{
		$('.sjjq').css('display','none')
		$('.psjq').css('display','block')
	}
})

/* 
tc列表采集 
 */
$('html body').on('click','.newsUserHomeBtn',function () {
	that =  $('.news_collect_process');
	home_url = window.location.href;
	user_id = home_url.split('/')[5];
	
	content_objs = [];
	content_ids = [];
	page = 0;
	mode = $("input[name='mode']:checked").val();
	wordsPrepend(that,'开始。。');
	//按照时间取
	if(mode == 1){
		//获取开始
		start_year = $('.start_year').val();
		start_month = $('.start_month').val();
		start_day = $('.start_day').val();
		
		end_year = $('.end_year').val();
		end_month = $('.end_month').val();
		end_day = $('.end_day').val();
		if(!start_day || !end_day){
			wordsPrepend(that,'请输入完整日期');
			return;
		}
		start_time = tranStrToTimestamps(start_year + '-' + start_month + '-' + start_day + " 00:00:00");
		end_time = tranStrToTimestamps(end_year + '-' + end_month + '-' + end_day + " 23:59:59");
		//请求item_id
		for(let i = 0;i<100;i++){
			tmp_has_more = false;
			data = homeList(user_id,page);
			if(data){
				content_objs = content_objs.concat(data.article_list);
				tmp_has_more = data.hasMore;
				page++;
			}
			if(!tmp_has_more){
				break;
			}
		}
		//筛出需要的content_ids
		if(content_objs.length > 0){
			for(content_obj of content_objs){
				if(content_obj.pub_time > start_time && content_obj.pub_time < end_time){
					content_ids.push(content_obj.vurl);
				}
			}
		}
		
	}
	
	//按照篇章取
	if(mode == 2){
		//获取input框
		start_index = $(".start_index").val()
		end_index = $(".end_index").val()
		if(!start_index || !end_index){
			wordsPrepend(that,'请输入开始和结束篇章');
			return;
		}
		page = 0;
		//请求item_id
		for(let i = 0;i<100;i++){
			tmp_has_more = false;
			data = homeList(user_id,i);
			if(data){
				content_objs = content_objs.concat(data.article_list);
				tmp_has_more = data.hasMore;
				max_behot_time = data.max_behot_time;
			}
			if(!(content_objs.length <  end_index && tmp_has_more)){
				break;
			}
			
		}
		//筛出需要的content_ids
		if(content_objs.length > 0){
			for(let i = start_index-1;i<end_index;i++){
				if(content_objs[i] == 'undefined'){
					break;
				}
				content_ids.push(content_objs[i].vurl);
			}
		}
	}
	
	console.log(content_ids);
	if(content_ids.length == 0){
		wordsPrepend(that,'无数据',1);
		return;
	}

	begin = 0;
	intt = setInterval(function(){
		wordsPrepend(that,content_ids[begin],1);
		window.open(content_ids[begin]);
		if((begin+1) >= content_ids.length ){
			wordsPrepend(that,'搬运完成',1);
			clearInterval(intt);
			return;
		}
		begin++;
	},9000);
	
	
	
	
});


/* 
腾讯搜索主页id 
 */
function homeList(user_id,page = 0){
	let url = 'https://pacaio.match.qq.com/om/mediaArticles';
	result = {};
	result.article_list = [];
	result.hasMore = true;
	$.ajax({
		url:url,
		type:"get",
		async:false,
		dataType:'json',
		data:{
			mid:user_id,
			num:15,
			page:page
		},
		success:function(data){
			if(data.msg == 'ok'){
			
				if(data.data){
					for(item of data.data){
						item_data = {};
						item_data.vurl = item.vurl;
						item_data.pub_time = item.timestamp;
						result.article_list.push(item_data);
					}
				}
				if(result.article_list.length < 15){
					result.hasMore = false;
				}
			}
		},
		error:function(){
			layer.msg('用户文章获取失败');
		}
	})
	return result;
}


